﻿using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace WJP.Serialization
{
    public class BinaryFormatterWrapper : ISerializationFormatter
    {
        public BinaryFormatter Formatter { get; } = new BinaryFormatter();

        /// <summary>
        /// 反序列化
        /// </summary>
        /// <param name="serializationStream"></param>
        /// <returns></returns>
        public object Deserialize(Stream serializationStream)
        {
            return this.Formatter.Deserialize(serializationStream);
        }

        /// <summary>
        /// 序列化
        /// </summary>
        /// <param name="serializationStream"></param>
        /// <param name="graph"></param>
        public void Serialize(Stream serializationStream, object graph)
        {
            this.Formatter.Serialize(serializationStream, graph);
        }
    }
}